package com.atguigu.study.controller;

import com.atguigu.study.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.parser.apache.tika.ApacheTikaDocumentParser;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @author Marco
 * @Description
 * @date 2025/8/22 23:17
 * @email 3293336923@qq.com
 */
@Slf4j
@RestController
public class RAGController {

    @Autowired
    EmbeddingStore<TextSegment> embeddingStore;

    @Autowired
    private ChatAssistant  chatAssistant;

    @GetMapping("embed/store/rag")
    public     String     testAdd() throws FileNotFoundException {
//        Document document = FileSystemDocumentLoader.loadDocument("");

        FileInputStream  fileInputStream = new FileInputStream("D:\\BaiduNetdiskDownload\\尚硅谷\\项目\\langchain4j\\状态码.xls");
        Document document = new ApacheTikaDocumentParser().parse(fileInputStream);

        EmbeddingStoreIngestor.ingest(document , embeddingStore);

        String result = chatAssistant.chat("编码值为102表示什么?");

        log.info("result:{}",result);
        return   result;
    }

}
